package com.android;

import java.io.OutputStreamWriter;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MemoryActivity extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
	static final int DIALOG_PAUSED_ID = 0;
	static final int DIALOG_GAMEOVER_ID = 1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //New Game button
        Button newgame = (Button) findViewById(R.id.newgame);
        //Highscore List button
    	Button highscore = (Button) findViewById(R.id.highscore);
    	//Exit button
    	Button exit = (Button) findViewById(R.id.exit);
    	//Credits button
    	Button credits = (Button) findViewById(R.id.credits);
    	//Setting the clickListeners to the 4 buttons
        newgame.setOnClickListener(this);
        highscore.setOnClickListener(this);
        exit.setOnClickListener(this);
        credits.setOnClickListener(this);
    }

    protected Dialog onCreateDialog(int id) {
        Dialog dialog = null;
        switch(id) {
        case DIALOG_PAUSED_ID:
            // do the work to define the pause Dialog
            break;
        case DIALOG_GAMEOVER_ID:
            // do the work to define the game over Dialog
            break;
        default:
            dialog = null;
        }
        return dialog;
    }
    
	@Override
	public void onClick(View v) {
		//checking what was pressed:
		if(v == findViewById(R.id.newgame)){
			//close the current activity
			this.finish();
			//start a new activity
    		Intent intent  = new Intent(getBaseContext(), GameBoard.class);
    		startActivity(intent);
		}else if(v == findViewById(R.id.highscore)){
			//close the current activity
			this.finish();
			//start a new activity
			Intent intent  = new Intent(getBaseContext(), HighScore.class);
    		startActivity(intent);
		}else if(v == findViewById(R.id.credits)){
			//close the current activity
			this.finish();
			//start a new activity
			Intent intent  = new Intent(getBaseContext(), Credits.class);
    		startActivity(intent);
		}else if(v == findViewById(R.id.exit)){
			//close the current activity = exit
			// prepare the alert box
            AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
 
            // set the text message
            alertbox.setMessage("Do you want to quit the game?");
 
            // add a neutral button to the alert box and assign a click listener
            alertbox.setCancelable(false)
            //if the player presses yes do this
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                	 //close the activity
                     MemoryActivity.this.finish();
                }
            })
            //if the player presses no do this
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                	//close the dialog box
                     dialog.cancel();
                }
            });
            // show it
            alertbox.show();
		}
		
	}
}